{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os \n",
    "\n",
    "\n",
    "import h5py    \n",
    "import numpy as np    \n",
    "import pdb\n",
    "\n",
    "import debugpy\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from os.path import join, split, exists,isdir\n",
    "\n",
    "\n",
    "\n",
    "def load_hdf5(file_name):\n",
    "    data = {}\n",
    "    with h5py.File(file_name, \"r\") as hdf:\n",
    "        # List the datasets inside the file\n",
    "        # print(\"Datasets:\", list(hdf.keys()))\n",
    "\n",
    "        for key,value in hdf.items():\n",
    "            if sum(ele for ele in value.shape) < 5 or \"version\" in key:\n",
    "                continue\n",
    "                # if value.dtype == \"|S5\":\n",
    "                #     res.append((key, str(value).replace(\"[\", \"\").replace(\"]\", \"\").replace(\"b'\", \"\").replace(\"'\", \"\")))\n",
    "                # else:\n",
    "                #     res.append((key, value))\n",
    "            else:\n",
    "                # res.append((key, value.shape))\n",
    "                data[key] = np.array(value)\n",
    "\n",
    "    return data \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = \"/baai-cwm-1/baai_cwm_ml/algorithm/shaocong.xu/exp/BlenderProc-3DFront/examples/datasets/front_3d_with_improved_mat/renderings_with_nocs/0a8d471a-2587-458a-9214-586e003e9cf9/0.hdf5\"\n",
    "\n",
    "data = load_hdf5(a)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['cam_Ts', 'class_segmaps', 'colors', 'depth', 'instance_segmaps', 'nocs', 'normals'])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[0, 1, 1],\n",
       "        [0, 1, 1],\n",
       "        [0, 1, 1],\n",
       "        ...,\n",
       "        [2, 3, 2],\n",
       "        [2, 3, 2],\n",
       "        [2, 3, 2]],\n",
       "\n",
       "       [[0, 1, 0],\n",
       "        [0, 1, 1],\n",
       "        [0, 1, 1],\n",
       "        ...,\n",
       "        [2, 3, 2],\n",
       "        [2, 3, 2],\n",
       "        [2, 3, 2]],\n",
       "\n",
       "       [[0, 1, 0],\n",
       "        [0, 1, 0],\n",
       "        [0, 1, 0],\n",
       "        ...,\n",
       "        [2, 3, 2],\n",
       "        [2, 3, 2],\n",
       "        [2, 3, 2]],\n",
       "\n",
       "       ...,\n",
       "\n",
       "       [[0, 1, 1],\n",
       "        [0, 1, 1],\n",
       "        [0, 1, 1],\n",
       "        ...,\n",
       "        [1, 1, 0],\n",
       "        [1, 1, 0],\n",
       "        [1, 1, 0]],\n",
       "\n",
       "       [[0, 1, 1],\n",
       "        [0, 1, 1],\n",
       "        [0, 1, 1],\n",
       "        ...,\n",
       "        [1, 1, 0],\n",
       "        [1, 1, 0],\n",
       "        [1, 1, 0]],\n",
       "\n",
       "       [[0, 1, 1],\n",
       "        [0, 1, 1],\n",
       "        [0, 1, 1],\n",
       "        ...,\n",
       "        [1, 1, 0],\n",
       "        [1, 1, 0],\n",
       "        [1, 1, 0]]], dtype=uint8)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
